package com.yh.correct.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yh.correct.dao.ILeavePersonnelMapper;
import com.yh.correct.model.LeavePersonnel;
import com.yh.correct.model.Page;
import com.yh.correct.service.ILeavePersonnelService;

/**
 * 
 * 外出请假条业务层实现类
 * @author swj
 *
 */
@Service("LeavePersonnelService")
public class LeavePersonnelServiceImpl implements ILeavePersonnelService {

	@Autowired
	private ILeavePersonnelMapper leavepersonnelmapper;
	

	@Override
	public int addLeavePersonnel(LeavePersonnel leavepersonnel) throws Exception{
		// TODO Auto-generated method stub
		return leavepersonnelmapper.addLeavePersonnel(leavepersonnel);
	}

	@Override
	public int delLeavePersonnel(LeavePersonnel leavepersonnel) throws Exception{
		// TODO Auto-generated method stub
		return leavepersonnelmapper.delLeavePersonnel(leavepersonnel);
	}

	/**
	 * 批量删除请假信息
	 * @param list
	 * @return
	 * @throws Exception
     */
	@Override
	public int deleteBatch(List<Integer> list) throws Exception {
		return leavepersonnelmapper.deleteBatch(list);
	}

	@Override
	public int editLeavePersonnel(LeavePersonnel leavepersonnel) throws Exception {
		// TODO Auto-generated method stub
		return leavepersonnelmapper.editLeavePersonnel(leavepersonnel);
	}

	/**
	 * 模糊查询用户信息列表
	 * @param leavepersonnel
	 * @return
	 * @throws Exception
     */
	@Override
	public Page getLikeLeavePersonnel(Map<String, Object> leavepersonnel) throws Exception {
		// TODO Auto-generated method stub
		Page page=new Page();
		page.setTotalNum(leavepersonnelmapper.getLikeLeavePersonnelCount(leavepersonnel));
		int pageSize = Integer.parseInt(String.valueOf(leavepersonnel.get("pageSize")));
		page.setPageSize(pageSize);
		int curPageNum = Integer.parseInt(String.valueOf(leavepersonnel.get("pageNum")));
		page.setCurPageNum(curPageNum);
		page.setTotalPage(page.getTotalNum()/pageSize+(page.getTotalNum()%pageSize==0?0:1));
		page.setResult(leavepersonnelmapper.getLikeLeavePersonnel(leavepersonnel));
		return page;
	}

	@Override
	public Map<String, Object> getLeavePersonnelById(LeavePersonnel leavepersonnel) throws Exception {
		// TODO Auto-generated method stub
		return  leavepersonnelmapper.getLeavePersonnelById(leavepersonnel);
	}

	/**
	 * 查询所有请假信息
	 * @return
	 * @throws Exception
     */
	@Override
	public List<Map<String,Object>> getAllLeavePersonnel() throws Exception {
		return leavepersonnelmapper.getAllLeavePersonnel();
	}

	/**
	 * 根据id查询请假信息
	 * @param leavepersonnel
	 * @return
	 * @throws Exception
     */
	@Override
	public Map<String, Object> getIdLeavePersonnel(LeavePersonnel leavepersonnel) throws Exception {
		return leavepersonnelmapper.getIdLeavePersonnel(leavepersonnel);
	}




	

}
